<?php
include_once('../includes/definer.php');
include_once(INC.'admin/php/clases/FileImage.php');

$nombre = 'img'.time().''.rand(1, 9999);
$ruta = INC.'content/tmp/que-hacemos/';

//validaciones
$ext = explode('.', $_FILES['files']['name'][0]);
$ext = '.'.$ext[count($ext)-1];
$ext = strtolower($ext);
$ext = ($ext == '.jpeg')?'.jpg':$ext;
if ($ext != '.jpg' && $ext != '.jpeg' && $ext != '.gif' && $ext != '.png' )exit($ext);

//original escalada
$fileImage = new FileImage($_FILES['files']['tmp_name'][0]);
$fileImage->escalar(700, 350);
$fileImage->save($ruta.'/o/'.$nombre);

//recortada
$fileImage = new FileImage($_FILES['files']['tmp_name'][0]);
$fileImage->escalar(700, 350);
$fileImage->recortarDesdeElCentro(700, 350);
$fileImage->save($ruta.$nombre);

//respuesta
$response = array (
    'files'=>array(
        array(
            'url'=>URL.'content/tmp/que-hacemos/o/'.$nombre.$ext,
            'galerry_url'=>URL.'content/tmp/que-hacemos/o/'.$nombre.$ext,
            'name'=>$_FILES['files']['name'][0],
            'nombre'=>$nombre,
            'extension'=>$fileImage->extension,
            'type'=>$_FILES['files']['type'][0],
            'size'=>$_FILES['files']['size'][0],
            'delete_url'=>'',
            'delete_type'=>'DELETE'
        )
    )
);
header("Content-type: application/json");
echo(json_encode($response));
?>
